#ifndef _KERNEL_H_
#define _KERNEL_H_

#include <td.h>
#include <sched.h>

/*
	STRUCTURES
*/

// Request structure
typedef struct __req {
  int call;             // system call number
  // NOTE: The result of using more arguments than are actually passed
  // by the system call is undefined; in practice, it will load these
  // values with garbage and probably crash.
  int a0;               // argument 0
  int a1;               // argument 1
  int a2;               // argument 2
  int a3;               // argument 3
  int a4;               // argument 4
} req;

/*
	ASSEMBLY CODE FUNCTIONS
*/

/* Exits the kernel into a user task previously interrupted by IRQ */
extern void KernelExitIRQ( td *task, req *request );

/* Exits the kernel into a user task previously interrupted by SWI */
extern void KernelExitSWI( td *task, req *request );

/* Kernel entry point for IRQ */
extern void KernelEnterIRQ();

/* Kernel entry point for SWI */
extern void KernelEnterSWI();

/*
	INITIALIZATION
*/

/* First user task. */ 
void UserInit();

/* Initializes the jump table and creates the first user task */
void Initialize( sched *s );

/* Schedules the next user task to execute with the highest priority */
td* Schedule( sched *s );

/* Exits the kernel, sets the task's state to ACTIVE and starts executing the user task */
void Activate( sched *s, td *task, req *request );

/* Handles the requested system call based on the parameters passed in the request */
void Handle( sched *s, td *task, req *request );

#endif
